package org.dromara.system.controller.talent;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.ServiceContentBo;
import org.dromara.system.domain.bo.ServiceContentLevelReqBo;
import org.dromara.system.domain.vo.ServiceContentVo;
import org.dromara.system.service.IServiceContentService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务内容
 *
 * @author 毛宁川
 * @date 2025-07-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/talent/ServiceContent")
public class ServiceContentController extends BaseController {

    private final IServiceContentService serviceContentService;

    /**
     * 查询服务内容列表
     */
    @SaCheckPermission("talent:ServiceContent:list")
    @GetMapping("/list")
    public TableDataInfo<ServiceContentVo> list(ServiceContentBo bo, PageQuery pageQuery) {
        return serviceContentService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出服务内容列表
     */
    @SaCheckPermission("talent:ServiceContent:export")
    @Log(title = "服务内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ServiceContentBo bo, HttpServletResponse response) {
        List<ServiceContentVo> list = serviceContentService.queryList(bo);
        ExcelUtil.exportExcel(list, "服务内容", ServiceContentVo.class, response);
    }

    /**
     * 获取服务内容详细信息
     *
     * @param serviceContentId 主键
     */
    @SaCheckPermission("talent:ServiceContent:query")
    @GetMapping("/{serviceContentId}")
    public R<ServiceContentVo> getInfo(@NotNull(message = "主键不能为空")
                                       @PathVariable Long serviceContentId) {
        return R.ok(serviceContentService.queryById(serviceContentId));
    }


    /**
     * 根据服务项目ID查询服务内容
     *
     * @param serviceItemId 服务项目ID
     */
    @SaCheckPermission("talent:ServiceContent:query")
    @GetMapping("/serviceContentList/{serviceItemId}")
    public R<List<ServiceContentVo>> findByServiceItemId(@NotNull(message = "服务项目ID不能为空")
                                                         @PathVariable Long serviceItemId) {
        return R.ok(serviceContentService.findByServiceItemId(serviceItemId));
    }

    /**
     * 新增服务内容
     */
    @SaCheckPermission("talent:ServiceContent:add")
    @Log(title = "服务内容", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ServiceContentLevelReqBo bo) {
        return toAjax(serviceContentService.insertByBo(bo));
    }

    /**
     * 修改服务内容
     */
    @SaCheckPermission("talent:ServiceContent:edit")
    @Log(title = "服务内容", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ServiceContentLevelReqBo bo) {
        return toAjax(serviceContentService.updateByBo(bo));
    }

    /**
     * 删除服务内容
     *
     * @param serviceContentIds 主键串
     */
    @SaCheckPermission("talent:ServiceContent:remove")
    @Log(title = "服务内容", businessType = BusinessType.DELETE)
    @DeleteMapping("/{serviceContentIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] serviceContentIds) {
        return toAjax(serviceContentService.deleteWithValidByIds(List.of(serviceContentIds), true));
    }
}
